package com.goodmr.passport.webapp.controller;

import com.goodmr.passport.webapp.Serivce.RegisterService;
import com.goodmr.passport.webapp.controller.SignupController;
import com.goodmr.passport.webapp.model.request.SignupReq;
import com.goodmr.passport.webapp.model.response.SignupResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 帐号注册实现
 *
 * @author <a href="mailto:bingdong13@msn.com">bigo</a>
 */
@RestController
@RequestMapping(path = "/passport/signup")
public class SignupController {

    private final RegisterService registerService;

    @Autowired
    public SignupController(RegisterService registerService) {
        this.registerService = registerService;
    }

    /**
     * 帐号密码注册
     *
     * @param body 请求数据包
     * @return 注册成功返回 token，否则返回异常
     */
    @PostMapping("")
    public ResponseEntity<SignupResp> register(@Valid @RequestBody SignupReq body) {

        SignupResp signupResp = registerService.register(body);

        return ResponseEntity.ok(signupResp);
    }
}